<?php
require(__DIR__ . '/vendor/autoload.php');

use RocketMqClient\RocketMqClient;

//这是服务器地址监听的端口，可以配置多个，每个配置启动一个进程处理消息
$config = [
    [
        'host'=>'localhost',
        'port'=>'9090'
    ]
];
$context_option = [
    'ssl' => [
        'local_cert'        => '/Users/gaork/Desktop/ssl/test/client.pem',
        'passphrase'        => '123123',
        'allow_self_signed' => true,
        'verify_peer'       => true
    ]
];
$context = stream_context_create($context_option);
// 发送普通消息
try {
    $client = new RocketMqClient( $config, $context);
    $res    = $client->sendMsg( 'test_topic', 'TagA', 'hello world ', 'msg_123' );
    if ($res['code'] == 0) {
        $msg_id = $res['msg_id'];
    }
}  catch (\Exception $e) {
    echo $e->getMessage();
}

//发送延时消息
/*try {
    $client = new RocketMqClient( $config );
    // $seconds 延时秒数，不能大于 40*24*60*60（40天），
    $res    = $client->sendDelayMsg( 'test_topic', 'TagA', 'hello world ', 10, 'msg_123' );
} catch (\Exception $e) {
    echo $e->getMessage();
}*/

//发送顺序消息
/*try {
    $client = new RocketMqClient( $config );
    //如果有$shardingKey 则为分区顺序消息
    $res    = $client->sendOrderMsg( 'test_topic', 'TagA', 'hello world ', 'msg_123', 'shard_1' );
} catch (\Exception $e) {
    echo $e->getMessage();
}*/